<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">计划单号：</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="planNo" class="layui-input" type="text"
                                               placeholder="请输入计划单号"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料编号：</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="skuCode" class="layui-input" type="text"
                                               placeholder="请输入物料编号"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料名称：</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="productName" class="layui-input" type="text"
                                               placeholder="请输入物料名称"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">时间段：</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="createTime" id="pTime" class="layui-input date-icon" type="text"
                                               placeholder="选择时间" style="width: 200px" readonly/>
                                    </div>
                                    <input name="startCreateTime" id="sTime" type="hidden"/>
                                    <input name="endCreateTime" id="eTime" type="hidden"/>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 表格 -->
            <table class="layui-table" id="erpPurchasePlanInfoTable" lay-filter="erpPurchasePlanInfoTable"></table>
        </div>
    </div>
</div>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laytpl', 'laydate', 'util'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var util = layui.util;

        //时间范围
        laydate.render({
            elem: '#pTime',
            type: 'date',
            range: true,
            done: function (value, date, endDate) {
                if (value) {
                    var dateValue = value.split(" - ");
                    $("#sTime").val(dateValue[0] + " 00:00:00");
                    $("#eTime").val(dateValue[1] + " 23:59:59");
                } else {
                    $("#sTime").val("");
                    $("#eTime").val("");
                }
            }
        });

        // 渲染表格
        var insTb = table.render({
            elem: '#erpPurchasePlanInfoTable',
            url: config.base + 'enterprise/purchase/admin/purchasePlanDetail/list',
            where: {
                order: "desc"
            },
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'},
                {field: 'planNo', align: 'center', title: '计划单号', width: 200},
                {field: 'departmentName', align: 'center', title: '申报部门'},
                {field: 'skuCode', align: 'center', title: '物料编号'},
                {field: 'productName', align: 'center', title: '物料名称'},
                {field: 'productCategory', align: 'center', title: '物料分类'},
                {field: 'specifications', align: 'center', title: '规格型号'},
                {field: 'unitName', align: 'center', title: '计量单位'},
                {field: 'purchaseNumber', align: 'center', title: '领料数量'},
                // {field: 'useAddress', align: 'center', title: '使用地址'},
                {field: 'createTime', align: 'center', title: '创建时间', width: 170},
            ]]
        });

        //监听排序
        table.on('sort(erpPurchasePlanInfoTable)', function (obj) {
            table.reload('erpPurchasePlanInfoTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            insTb.reload({where: admin.resetSearch(data.field), page: {curr: 1}}, 'data');
        });

        // 导出excel
        $('#erpPurchasePlanInfoBtnExport').click(function () {
            var checkRows = table.checkStatus('erpPurchasePlanInfoTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

    });
</script>